/**
 * @file Intermediate.cpp
 * @author GalaktiK (jacobliu001@qq.com)
 * @version 1.0
 * @date 2020-12-25
 *
 * @copyright Copyright (c) 2020, Distributed under License GPLv2
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string getOct(ll x) {
    string str;
    stringstream ss;
    ss << oct << x;
    ss >> str;
    return str;
}

ll octToLL(string str) {
    ll r;
    stringstream ss;
    ss << str;
    ss >> oct >> r;
    return r;
}

ll getSumDig(ll x) {
    ll ret = 0;
    while (x != 0) {
        ret += (x % 8);
        x /= 8;
    }
    return ret;
}

int main() {
    for (int TC = 1; TC <= 5; TC++) {
        string ss, sd;
        ll r;
        cin >> ss >> sd >> r;
        ll s, d;
        s = octToLL(ss);
        d = octToLL(sd);
        ll acc = 0;
        for (ll p = r * (r-1) / 2; p < r * (r+1) / 2; p++) {
            acc += getSumDig(s + p * d);
        }
        cout << TC << ". " << acc << endl;
    }
}
